<!-- src/components/CustomDialog.vue -->
<template>
  <div v-if="visible" class="dialog-overlay" @click.self="handleClose">
    <div class="dialog-container" :style="{ width: width, marginTop: top }">
      <div class="dialog-header">
        <slot name="title">
          <span class="dialog-title">回写图片</span>
        </slot>
        <button class="dialog-close" @click="handleClose">×</button>
      </div>
      <div class="dialog-body">
        <ul>
             <li style="color: #409eff; font-size: 24px">
                用户名称：<span>{{ fromJson.buyName }}</span>
             </li>
          <li style="color: #409eff; font-size: 24px">
            <p>
                类型：
              <span v-if="fromJson.lotteryType == 1">直选</span>
              <span v-if="fromJson.lotteryType == 2">组三</span>
              <span v-if="fromJson.lotteryType == 3">组六</span>
              <span v-if="fromJson.lotteryType == 4">单选</span>
            </p>
          </li>
          <li style="color: #409eff; font-size: 24px; display: flex">
            <div v-if="fromJson.lotteryType == 1">
              <p style="margin-right: 10px; color: rgb(243, 156, 18)">
                组：<span>{{ fromJson.buyGroup }}</span>
              </p>
              <p style="color: rgb(39, 174, 96)">
                直：<span>{{ fromJson.multiple }}</span>
              </p>
            </div>
            <div v-else>
              <p style="color: rgb(39, 174, 96)">
                倍：<span>{{ fromJson.multiple }}</span>
              </p>
            </div>
          </li>
          <li style="color: #409eff; font-size: 24px; display: flex">
            <p style="color: #409eff; font-size: 24px">票号</p>
            <div v-if="fromJson.lotteryNo" style="width: 80%; display: flex; align-items: center; display: flex; flex-wrap: wrap">
              <p style="width: 16%; text-align: center" v-for="(item, index) in fromJson.lotteryNo.split(',')" :key="index">
                {{ item }}
              </p>
            </div>
          </li>
        </ul>
      </div>
      <div class="dialog-footer" v-if="$slots.footer">
        <slot name="footer"></slot>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "CustomDialog",
  data() {
    return {
      visible: false,
      fromJson: {},
    };
  },
  props: {
    width: {
      type: String,
      default: "1000px",
    },
    top: {
      type: String,
      default: "15vh",
    },
    closeOnClickModal: {
      type: Boolean,
      default: true,
    },
  },
  methods: {
    open(form) {
      console.log("回写过来的数据");
      console.log(form);
      if (form.lotteryType && form.buyName && form.lotteryNo) {
        this.fromJson = form;
      }
      this.visible = true;
    },
    handleClose() {
      this.$emit("update:visible", false);
      this.$emit("close");
      this.visible = false;
    },
  },
  watch: {},
  beforeDestroy() {
    document.body.style.overflow = "";
  },
};
</script>

<style scoped>
p {
  margin: 0;
  margin-top: 10px;
}
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  animation: fadeIn 0.3s ease-out;
}

.dialog-container {
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  animation: slideIn 0.3s ease-out;
}

.dialog-header {
  padding: 20px 20px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #ebeef5;
}

.dialog-title {
  font-size: 18px;
  font-weight: 600;
  color: #303133;
}

.dialog-close {
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #909399;
  outline: none;
}

.dialog-close:hover {
  color: #409eff;
}

.dialog-body {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
  max-height: 60vh;
  min-height: 60vh;
  background-color: #f0f9eb;
  border-color: #e1f3d8;
}

.dialog-footer {
  padding: 15px 20px;
  text-align: right;
  border-top: 1px solid #ebeef5;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    transform: translateY(-60px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .dialog-container {
    width: 90% !important;
    margin: 10vh auto !important;
  }
}
</style>
